package cn.edu.zucc.controller;

import cn.edu.zucc.entity.TArticle;
import cn.edu.zucc.service.TArticleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description t_article
 * @author zhengkai.blog.csdn.net
 * @date 2022-04-17
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/tArticle")
public class TArticleController {

    @Resource
    private TArticleService tArticleService;

/**
* id 存在就更新 不然插入
* @param tArticle
* @return
*/
@PostMapping("/save")
public Object save(@RequestBody TArticle tArticle){
return tArticleService.save(tArticle);
}

    /**
    * 新增
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/insert")
//    public Object insert(TArticle tArticle){
//        System.out.println("tArticle");
//        System.out.println(tArticle);
//        return tArticleService.insert(tArticle);
//    }
    public Object insert(@RequestBody  TArticle tArticle){
        System.out.println(tArticle);
//        Map<String,String> map=new HashMap<>();
//        new Map<>();
//        map.put("1","1");
////        map.put("1","1");
//        return map;
        return tArticleService.insert(tArticle);
    }

    /**
    * 刪除
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/delete")
    public Object delete(int id){
        return tArticleService.delete(id);
    }
//    public Object delete(int id){
//        return tArticleService.delete(id);
//    }

    /**
    * 更新
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/update")
    public Object update(TArticle tArticle){
        return tArticleService.update(tArticle);
    }

    /**
    * 查询 根据主键 id 查询
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/getById")
    public Object getById(Integer id){
        return tArticleService.getById(id);
    }

    /**
    * 查询 分页查询
    * @author zhengkai.blog.csdn.net
    * @date 2022/04/17
    **/
    @PostMapping("/list")
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int pageNumber,
                                        @RequestParam(required = false, defaultValue = "10") int pageSize) {
        return tArticleService.pageList(pageNumber, pageSize);
        //Map<String, Object> pageList = tArticleService.pageList(pageNumber, pageSize);
//return ReturnT.success(pageList);
    }

}
